
*********************************
** USE THIS DO FILE TO RUN MAIN MANUSCRIPT ANALYSES
** CREATED: DEC 2023
** BY: CC
*********************************

*****************
* PROGRAM SETUP *
*****************

version 17
clear all
set more off
set scheme plotplainblind, permanently


***************
* DIRECTORIES *
***************

global pathown = "/Users/cavaille/Dropbox/CO.who_cares/2.Data and Analyses"

global pathcode = "$pathown/7.Replication file PSRM"
global pathdata = "$pathown/7.Replication file PSRM/data"
global pathtemp = "$pathown/7.Replication file PSRM/temp"
global pathout = "$pathown/7.Replication file PSRM/out"
global pathfig = "$pathown/7.Replication file PSRM/fig"
global pathtab = "$pathown/7.Replication file PSRM/tab"

do "$pathcode/0.config.do" 


log using "$pathcode/log_appendix.log", replace

*----- 
*-------------------------------
*---  C. Survey design. Sample sizes  (Table C1)



cd "$pathtemp"

matrix EV = J(9,3,0)
matrix colnames EV = "Likert" "Likert +" "QVSR" 
matrix rownames EV = "Observations (dup incl)" ///
"Individuals (dup excl)" /// 
"Duplicate rate" ///
"Donation task (dup excluded)" /// 
"Gender (dup excluded)" /// 
"Drop out rate (as a share of ind.)" ///
"Loss rate (as a share of obs.)" ///
"DG (dup excl)" ///
"Letter Writing (dup excl)" 



*-- FIRST ROW: wave 1, how many observations do we start with , duplicates included?
use "$pathdata/part1_wave1_qualtrics.dta", replace
** destring
destring block, replace
destring treatment, replace
destring id, replace

**- rename 
rename I_Session session

**- drop if treatment == 7 [a small subset of respondents received a different version of QVSR, this was a pilot used for a separate study, we consequently drop these observations]
drop if treatment == 7 

**- generate treatment variable [within each treatment branch, we further randomised respondents into receiving versus not receiving a partisan prime. Our treatment failed to manipulate partisan identity and had no effect on policy preferences. We thus pool primed and non-primed observations.]
gen method = treatment
recode method (1 4 = 1) ( 2 5 = 2) ( 3 6 = 3) 

label variable method	"Survey method treatment"
label define method_lbl 1   "Likert", add
label define method_lbl 2   "Likert+", add
label define method_lbl 3   "QVSR", add
label define method_lbl 999   "Dropped out before being assigned to treatment", add
label values method method_lbl

**- drop if dropped out before being assigned to treatment 
drop if method == 999


**- drop observations (14 in total) generated by authors during last minute sanity check 


**- test, no id
drop if id == .
**- CC's birthdate
drop if id == 13041984
**- if over a billion
drop if id > 1000000000


gen ICN = .
replace ICN = 1 if ICN_Q2 == 1
replace ICN = 0 if ICN_Q2 == 2

label variable ICN	"Informed consent page"
label define ICN_lbl 1   "Consented", add
label define ICN_lbl 0   "Did not consent", add
label values ICN ICN_lbl


** Number of observations (conditional on consenting), this includes duplicates
tab ICN if method == 1 & ICN == 1
matrix EV[1,1] = r(N)
local consent1 = r(N)
tab ICN if method == 2 & ICN == 1
matrix EV[1,2] = r(N)
local consent2 = r(N)
tab ICN if method == 3 & ICN == 1
matrix EV[1,3] = r(N)
local consent3 = r(N)


sort id session StartDate
quietly by id : gen n = _n

quietly bys id : gen dup = cond(_N==1,0,_n)
tab dup n 

quietly bys id : gen dupF = cond(_N==1,0,_n)
tab dupF 

*-- SECOND ROW: wave 1, how many unique individuals, conditional on consenting 
tab ICN if method == 1 & ICN == 1 & dupF < 2
matrix EV[2,1] = r(N)
local consenta1 = r(N)
tab ICN if method == 2 & ICN == 1 & dupF < 2
matrix EV[2,2] = r(N)
local consenta2 = r(N)
tab ICN if method == 3 & ICN == 1 & dupF < 2
matrix EV[2,3] = r(N)
local consenta3 = r(N)


*-- THIRD ROW: wave 1, duplicate rate 
matrix EV[3,1] = ((`consent1'-`consenta1')/`consent1') * 100
matrix EV[3,2] = ((`consent2'-`consenta2')/`consent2' ) * 100
matrix EV[3,3] = ((`consent3'-`consenta3')/`consent3' ) * 100



*-- FOURTH and FITH ROWS: number of observations used for the main analyses (e.g., Fig2 and Fig4), focusing on wave 1
use "$pathout/dataset_final.dta", replace

** flag observations used in the main donation analysis  (Fig 2 in main manuscript)
gen comp_bev_w1 = 0
replace comp_bev_w1 = 1 if votes_AAw1 < . & votes_gunw1 < . & votes_wallw1 < . & votes_paidLw1 < . & ///
votes_genderw1 < . & votes_gayw1 < . & votes_minWw1 < . & votes_abortionw1 < . & votes_deficitw1 < . & ///
votes_envirow1 < . & don_C_gun < . 

tab comp_bev_w1 if method == 1 & comp_bev_w1 == 1 
matrix EV[4,1] = r(N)
tab comp_bev_w1 if method == 2 & comp_bev_w1 == 1 
matrix EV[4,2] = r(N)
tab comp_bev_w1 if method == 3 & comp_bev_w1 == 1 
matrix EV[4,3] = r(N)

** flag observations used in the main exposure analysis (Fig 4 and 5 in main manuscript)
gen comp_exp_w1 = 0
replace comp_exp_w1 = 1 if votes_AAw1 < . & votes_gunw1 < . & votes_wallw1 < . & votes_paidLw1 < . & ///
votes_genderw1 < . & votes_gayw1 < . & votes_minWw1 < . & votes_abortionw1 < . & votes_deficitw1 < . & ///
votes_envirow1 < . & sex < . 

tab comp_exp_w1 if method == 1 & comp_exp_w1 == 1 
matrix EV[5,1] = r(N)
local used1 = r(N)
tab comp_exp_w1 if method == 2 & comp_exp_w1 == 1 
matrix EV[5,2] = r(N)
local used2 = r(N)
tab comp_exp_w1 if method == 3 & comp_exp_w1 == 1 
matrix EV[5,3] = r(N)
local used3 = r(N)


*-- SIXTH ROW: How many unique  individuals drop out 
matrix EV[6,1] = (1 - (`used1'/`consenta1')) * 100
matrix EV[6,2] = (1 - (`used2'/`consenta2')) * 100
matrix EV[6,3] = (1 - (`used3'/`consenta3')) * 100


*-- SEVENTH ROW: How many attempts at taking the survey do not produce a usable observations
matrix EV[7,1] = (1 - (`used1'/`consent1')) * 100
matrix EV[7,2] = (1 - (`used2'/`consent2')) * 100
matrix EV[7,3] = (1 - (`used3'/`consent3')) * 100

*--- EIGHTH AND NINETH ROWS: number of observations used for the main analyses (e.g., Fig3), focusing on wave 2
** flag observations used in the DG analysis  (Fig 3 in main manuscript)
gen comp_DG_w2 = 0
replace comp_DG_w2 = 1 if votes_AAw1 < . & votes_gunw1 < . & votes_wallw1 < . & votes_paidLw1 < . & ///
votes_genderw1 < . & votes_gayw1 < . & votes_minWw1 < . & votes_abortionw1 < . & votes_deficitw1 < . & ///
votes_envirow1 < . & punish_FaST < . 


tab comp_DG_w2 if method == 1 & comp_DG_w2 == 1
matrix EV[8,1] = r(N)
tab comp_DG_w2 if method == 2 & comp_DG_w2 == 1
matrix EV[8,2] = r(N)
tab comp_DG_w2 if method == 3 & comp_DG_w2 == 1
matrix EV[8,3] = r(N)


** flag observations used in the letter writing analysis (Fig 3 in main manuscript)
gen comp_write_w2 = 0
replace comp_write_w2 = 1 if votes_AAw1 < . & votes_gunw1 < . & votes_wallw1 < . & votes_paidLw1 < . & ///
votes_genderw1 < . & votes_gayw1 < . & votes_minWw1 < . & votes_abortionw1 < . & votes_deficitw1 < . & ///
votes_envirow1 < . & wrote < . 


tab comp_write_w2 if method == 1 & comp_write_w2 == 1
matrix EV[9,1] = r(N)
tab comp_write_w2 if method == 2 & comp_write_w2 == 1
matrix EV[9,2] = r(N)
tab comp_write_w2 if method == 3 & comp_write_w2 == 1
matrix EV[9,3] = r(N)




cd "$pathtab"

*****************

esttab  matrix(EV, fmt("0 0")) using tab_C1.tex, replace

**********************************************************
* OUTPUT TAB C1.                                         *
* PLEASE RUN CORRESPONDING LATEX FILE AVAILABLE IN "TAB" *
**********************************************************


*----- 
*-------------------------------
*---  C. Survey design. balance tables (Table C2 - C3 and C4)


use "$pathout/dataset_final.dta", replace

gen comp_bev_w1 = 0
replace comp_bev_w1 = 1 if votes_AAw1 < . & votes_gunw1 < . & votes_wallw1 < . & votes_paidLw1 < . & ///
votes_genderw1 < . & votes_gayw1 < . & votes_minWw1 < . & votes_abortionw1 < . & votes_deficitw1 < . & ///
votes_envirow1 < . & don_C_gun < . 

keep if comp_bev_w1 ==1
tab method, gen(meth)
tab xparty7, gen(prty)
recode ppeducat 1=2
tab ppeducat, gen(educ)
recode gunOa (2 3 = 0) (4 = 1)
recode ppethm (5 =3)
tab ppethm, gen(ethnic)
recode minWa (1=0) (2 3 = 1)
replace minWa = 99 if minWa == . 
tab minWa, gen(MW)
** child and gun all good parents_immi gay, not missing many_ ex: tab gunOa comp_exp_w1, miss
replace Nevangelical = 99 if Nevangelical == . 
tab Nevangelical, gen(BA)
replace evangelical = (evangelical * -1) +3


rename don_C_gun Donation_gun
rename don_C_wall_in Donation_immi
rename xparty7 Party_ID
rename xideo Ideology
rename educ1 HS_or_less
rename educ2 Some_college
rename educ3 BA
rename ppage Age
rename sex Gender
rename ethnic1 White
rename ethnic2 Black
rename ethnic3 Other
rename ethnic4 Hispanic
rename MW2 Exp_minW
rename MW3 MissV_minW
rename child2 Paid_leave_exp
rename gunOa Gun_exp
rename parents_immi Immi_exp
rename gay Sexual_orientation
rename evangelical Born_again
rename BA3 MissV_BA

balancetable meth1 Donation_gun Donation_immi Party_ID Ideology HS_or_less ///
 Some_college BA Age Gender White Black Other Hispanic ///
 Exp_minW MissV_minW Paid_leave_exp Gun_exp Immi_exp Sexual_orientation ///
 Born_again MissV_BA ///
 using "bal1.tex",  ctitles("Likert+/QVSR (pooled)" "Likert" "Difference") replace

balancetable meth2 Donation_gun Donation_immi Party_ID Ideology HS_or_less ///
 Some_college BA Age Gender White Black Other Hispanic ///
 Exp_minW MissV_minW Paid_leave_exp Gun_exp Immi_exp Sexual_orientation ///
 Born_again MissV_BA ///
 using "bal2.tex",  ctitles("Likert/QVSR (pooled)" "Likert+" "Difference") replace

balancetable meth3 Donation_gun Donation_immi Party_ID Ideology HS_or_less ///
 Some_college BA Age Gender White Black Other Hispanic ///
 Exp_minW MissV_minW Paid_leave_exp Gun_exp Immi_exp Sexual_orientation ///
 Born_again MissV_BA ///
 using "bal3.tex",  ctitles("Likert/Likert+ (pooled)" "QVSR" "Difference") replace




***********************************************************
* OUTPUT TAB C2, TAB C3 and TAB C4                        *
* PLEASE RUN CORRESPONDING LATEX FILES AVAILABLE IN "TAB" *
***********************************************************




*----- 
*-------------------------------
*---  C. Survey design. Attrition, Table C5


***-- build a dataset of all observations who match following conditions:
* consented
* finished part 1, meaning saw the items on proximity to childbirth and minwage
***-- then match to SES variables provided by IPSOS



use "$pathdata/part1_wave1_qualtrics.dta", replace
** destring
destring block, replace
destring treatment, replace
destring id, replace

**- rename 
rename I_Session session

**- drop if treatment == 7 [a small subset of respondents received a different version of QVSR, this was a pilot used for a separate study, we consequently drop these observations]
drop if treatment == 7 

**- generate treatment variable [within each treatment branch, we further randomised respondents into receiving versus not receiving a partisan prime. Our treatment failed to manipulate partisan identity and had no effect on policy preferences. We thus pool primed and non-primed observations.]
gen method = treatment
recode method (1 4 = 1) ( 2 5 = 2) ( 3 6 = 3) 

label variable method	"Survey method treatment"
label define method_lbl 1   "Likert", add
label define method_lbl 2   "Likert+", add
label define method_lbl 3   "QVSR", add
label define method_lbl 999   "Dropped out before being assigned to treatment", add
label values method method_lbl

**- drop if dropped out before being assigned to treatment 
drop if method == 999


**- drop observations (14 in total) generated by authors during last minute sanity check 


**- test, no id
drop if id == .
**- CC's birthdate
drop if id == 13041984
**- if over a billion
drop if id > 1000000000


gen ICN = .
replace ICN = 1 if ICN_Q2 == 1
replace ICN = 0 if ICN_Q2 == 2

label variable ICN	"Informed consent page"
label define ICN_lbl 1   "Consented", add
label define ICN_lbl 0   "Did not consent", add
label values ICN ICN_lbl

**- keep if consented
keep if ICN == 1 


**-- flag duplicates 

quietly bys id : gen dup = cond(_N==1,0,_n)

recode dup ( 1/10 = 1), gen(restart)

tab restart method, col

**--- match to SES 


destring xideo xpppa1690, replace

merge m:1 id using "$pathdata/ses_ipsos.dta"
drop if _merge == 2
drop _merge 

**-- code predictors 
do "$pathcode/0.code_var_SES_F.do"

**-- flag missing values 
gen miss_child = 1 if child2 == . 
replace miss_child = 0 if child2 != . 
replace child2 = 99 if child2 == . 

gen inc_miss = 0
replace inc_miss = 1 if ppincimp >= .  
replace ppincimp = 99 if ppincimp >= .  

tab method, gen(meth)
tab xparty7, gen(prty)
recode ppeducat 1=2
tab ppeducat, gen(educ)
recode gunOa (2 3 = 0) (4 = 1)
recode ppethm (5 =3)
tab ppethm, gen(ethnic)
recode minWa (1=0) (2 3 = 1)
replace minWa = 99 if minWa == . 
tab minWa, gen(MW)
replace Nevangelical = 99 if Nevangelical == . 
tab Nevangelical, gen(BA)
replace evangelical = (evangelical * -1) +3



**** flag IDs that made it into the final sample for the gun donation analysis 
preserve 
use "$pathout/dataset_final.dta", replace

gen comp_exp_w1 = 0
replace comp_exp_w1 = 1 if votes_AAw1 < . & votes_gunw1 < . & votes_wallw1 < . & votes_paidLw1 < . & ///
votes_genderw1 < . & votes_gayw1 < . & votes_minWw1 < . & votes_abortionw1 < . & votes_deficitw1 < . & ///
votes_envirow1 < . & sex < . 

keep if comp_exp_w1 == 1 

quietly bys id : gen dupF = cond(_N==1,0,_n)

gen drop_out = 0 
replace drop_out = 99 if dupF > 1 
keep id drop_out comp_exp_w1 method
keep if drop_out < . 


save "$pathtemp/ids_dataset_final.dta", replace
restore 

*** flag dup in the baseline data
quietly bys id : gen dupO = cond(_N==1,0,_n)


merge m:1 id method using "$pathtemp/ids_dataset_final.dta"

*** obs that dropped out 
replace drop_out = 1 if _merge == 1
** obs that duplicate 
replace drop_out = 1 if drop_out == 99 


tab drop_out method , col



** gen table 

gen Likert = drop_out
gen Likert_plus = drop_out
gen QVSR = drop_out

reg Likert  c.xparty7 c.xideo educ2 educ3 c.ppage  sex  ethnic2 ethnic3 ethnic4  MW2 MW3  c.child2  i.gunOa ///
parents_immi  i.gay  BA2 BA3 c.ppincimp if method == 1
estimates store dropw1

reg Likert_plus c.xparty7 c.xideo educ2 educ3 c.ppage  sex  ethnic2 ethnic3 ethnic4  MW2 MW3  c.child2  i.gunOa ///
parents_immi  i.gay   BA2 BA3 c.ppincimp if method == 2
estimates store dropw2

reg QVSR  c.xparty7 c.xideo educ2 educ3 c.ppage  sex  ethnic2 ethnic3 ethnic4  MW2 MW3  c.child2  i.gunOa ///
parents_immi i.gay  BA2 BA3 c.ppincimp if method == 3 
estimates store dropw3

cd "$pathtab"


esttab dropw1 dropw2 dropw3 using attrition.tex, replace ///
style(tex) cells(b(star fmt(3)) se(par(( )) fmt(3))) starlevels(* .05 ** .01 *** .001) ///
stats(N, fmt(0)) ///
drop(0.gunOa 0.gay) ///
varlabels(_cons cons ///
xparty7 Partisanship ///
xideo Ideology ///
educ2 Some_College ///
educ3 BA ///
ppage Age ///
sex Gender ///
ethnic2 Black ///
ethnic3 Other ///
ethnic4 Hispanic ///
MW2 Exp_minW ///
MW3 MissV_minW ///
child2 Paid_leave_exp ///
1.gunOa Gun_exp ///
parents_immi Immi_exp ///
1.gay Sexual_orientation ///
BA2 Born_again ///
BA3 MissV_BA ///
ppincimp income)


***********************************************************
* OUTPUT TAB C5                            				  *
* PLEASE RUN CORRESPONDING LATEX FILE AVAILABLE IN "TAB" *
***********************************************************



*----- 
*-------------------------------
*---  C. Survey design. Participation in wave 2 using all observable covariates (Table C6)



use "$pathout/dataset_final.dta", replace

*** drop people not eligible
gen comp_bev_w1 = 0
replace comp_bev_w1 = 1 if votes_AAw1 < . & votes_gunw1 < . & votes_wallw1 < . & votes_paidLw1 < . & ///
votes_genderw1 < . & votes_gayw1 < . & votes_minWw1 < . & votes_abortionw1 < . & votes_deficitw1 < . & ///
votes_envirow1 < . & don_C_gun < . 
keep if comp_bev_w1 == 1 



*** identify folks who consented in wave 2
preserve 
use "$pathdata/part1_wave2_qualtrics.dta", replace

rename mno id
rename state2 session

rename xtreat method
drop if method == 7

drop if id == .
drop if ICN_Q2 == "No"


**-- will be matched to eligible using id , so need to address doublons
quietly bys id  :  gen dup_p1 = cond(_N==1,0,_n)
tab dup_p1
**--- 74 doublons

**- order in which showed up in survey wave 2
sort id StartDate 
** generate the order variable
quietly by id   : gen n_p1 = _n

** keep the first one 
keep if dup_p1 == 0 | dup_p1 > 0 & n_p1 == 1 

drop dup_p1 n_p1 

gen wave2_p = 1
keep id wave2_p

rename id id_w2
*** merge wave 2 with wave 1 IDs

merge 1:1 id_w2 using "$pathdata/mno_id_W1W2.dta"
keep if _merge == 3 
drop _merge id_w2
rename id_w1 id 

save "$pathtemp/ids_wave2.dta", replace
restore 


**** merge 
merge m:1 id using "$pathtemp/ids_wave2.dta"
tab wave2_p _merge, miss
replace wave2_p = 0 if _merge == 1 & wave2_p == . 


tab method, gen(meth)
recode ppeducat 1=2
tab ppeducat, gen(educ)
recode gunOa (2 3 = 0) (4 = 1)
recode ppethm (5 =3)
tab ppethm, gen(ethnic)
recode minWa (1=0) (2 3 = 1)
replace minWa = 99 if minWa == . 
tab minWa, gen(MW)
replace Nevangelical = 99 if Nevangelical == . 
tab Nevangelical, gen(BA)
replace evangelical = (evangelical * -1) +3

gen Likert = wave2_p
gen Likert_plus = wave2_p
gen QVSR = wave2_p

reg Likert c.xparty7  c.xideo educ2 educ3 c.ppage  sex  ethnic2 ethnic3 ethnic4  ///
 MW2 MW3  c.child2  i.gunOa ///
parents_immi  i.gay  BA2 BA3 c.ppincimp if method == 1
estimates store bet1

reg Likert_plus c.xparty7  c.xideo educ2 educ3 c.ppage  sex  ethnic2 ethnic3 ethnic4  ///
 MW2 MW3  c.child2  i.gunOa ///
parents_immi  i.gay  BA2 BA3 c.ppincimp if method == 2
estimates store bet2

reg QVSR c.xparty7  c.xideo educ2 educ3 c.ppage  sex  ethnic2 ethnic3 ethnic4  ///
 MW2 MW3  c.child2  i.gunOa ///
parents_immi  i.gay  BA2 BA3 c.ppincimp if method == 3
estimates store bet3

cd "$pathtab"

esttab bet1 bet2 bet3  using attrition_betweenv1.tex, replace ///
style(tex) cells(b(star fmt(3)) se(par(( )) fmt(3))) starlevels(* .05 ** .01 *** .001) ///
stats(N, fmt(0)) ///
drop(0.gunOa 0.gay) ///
varlabels(_cons cons ///
xparty7 Partisanship ///
xideo Ideology ///
educ2 Some_College ///
educ3 BA ///
ppage Age ///
sex Gender ///
ethnic2 Black ///
ethnic3 Other ///
ethnic4 Hispanic ///
MW2 Exp_minW ///
MW3 MissV_minW ///
child2 Paid_leave_exp ///
1.gunOa Gun_exp ///
parents_immi Immi_exp ///
1.gay Sexual_orientation ///
BA2 Born_again ///
BA3 MissV_BA ///
ppincimp income)

*reg wave2_p i.ethnic2##i.method i.ethnic3##i.method i.ethnic4##i.method i.gunOa##i.method

**********************************************************
* OUTPUT TAB C6                           				 *
* PLEASE RUN CORRESPONDING LATEX FILE AVAILABLE IN "TAB" *
**********************************************************



*----- 
*-------------------------------
*---  C. Survey design. Participation in wave 2 using w1 preferences (Table C7)


reg Likert c.don_C_gun c.don_C_wall_in abs_votes_gunw1 abs_votes_wallw1 ///
abs_votes_minWw1 abs_votes_abortionw1 ///
if method == 1
estimates store bet1a

reg Likert_plus c.don_C_gun c.don_C_wall_in abs_votes_gunw1 abs_votes_wallw1 ///
abs_votes_minWw1 abs_votes_abortionw1 ///
if method == 2
estimates store bet2a

reg QVSR c.don_C_gun c.don_C_wall_in abs_votes_gunw1 abs_votes_wallw1 ///
abs_votes_minWw1 abs_votes_abortionw1 ///
if method == 3
estimates store bet3a


esttab bet1a bet2a bet3a  using attrition_betweenv2.tex, replace ///
style(tex) cells(b(star fmt(3)) se(par(( )) fmt(3))) starlevels(* .05 ** .01 *** .001) ///
stats(N, fmt(0)) ///
title(Predicting Participation in Wave 2 Using Wave 1 Donations and Opinions \label{attritionv2}) ///
varlabels(_cons cons ///
don_C_gun Donation_gun ////
don_C_wall_in Donation_immi ///
abs_votes_gunw1 Opinion_gun_abs  ///
abs_votes_wallw1 Opinion_wall_abs ///
abs_votes_minWw1 Opinion_minW_abs ///
abs_votes_abortionw1 Opinion_abortion_abs )

*reg wave2_p c.abs_votes_wallw1##i.method 


**********************************************************
* OUTPUT TAB C7                           				 *
* PLEASE RUN CORRESPONDING LATEX FILE AVAILABLE IN "TAB" *
**********************************************************


*----- 
*-------------------------------
*---  D. Using Wave 2 preferences (Fig D1)

use "$pathout/dataset_final.dta", replace

matrix EV = J(6,6,0)
matrix colnames EV = "Likert" " " "Likert +" " " "QVSR" " " 
matrix rownames EV = "Gun-related Donations" ///
"Immigration-related Donations" ///
"Minimum Wage-related Writing" /// 
"Abortion-related Writing" ///
"Punish abs" ///
"Punish proportion"


regress don_C_gunST c.votes_gunw2LPP3N##i.method i.block
lincom c.votes_gunw2LPP3N + 1.method#c.votes_gunw2LPP3N 
matrix EV[1,1] = r(estimate)
matrix EV[1,2] = r(se)
lincom c.votes_gunw2LPP3N + 2.method#c.votes_gunw2LPP3N 
matrix EV[1,3] = r(estimate)
matrix EV[1,4] = r(se)
lincom c.votes_gunw2LPP3N + 3.method#c.votes_gunw2LPP3N 
matrix EV[1,5] = r(estimate)
matrix EV[1,6] = r(se)


regress don_C_wall_inST c.votes_wall_inw2LPP3N##i.method  i.block
lincom c.votes_wall_inw2LPP3N + 1.method#c.votes_wall_inw2LPP3N 
matrix EV[2,1] = r(estimate)
matrix EV[2,2] = r(se)
lincom c.votes_wall_inw2LPP3N + 2.method#c.votes_wall_inw2LPP3N 
matrix EV[2,3] = r(estimate)
matrix EV[2,4] = r(se)
lincom c.votes_wall_inw2LPP3N + 3.method#c.votes_wall_inw2LPP3N 
matrix EV[2,5] = r(estimate)
matrix EV[2,6] = r(se)


regress writing_minWNST c.abs_votes_minWw2LPP3N##i.method  i.block
lincom c.abs_votes_minWw2LPP3N + 1.method#c.abs_votes_minWw2LPP3N , level(90)
matrix EV[3,1] = r(estimate)
matrix EV[3,2] = r(se)
lincom c.abs_votes_minWw2LPP3N + 2.method#c.abs_votes_minWw2LPP3N , level(90)
matrix EV[3,3] = r(estimate)
matrix EV[3,4] = r(se)
lincom c.abs_votes_minWw2LPP3N + 3.method#c.abs_votes_minWw2LPP3N , level(90)
matrix EV[3,5] = r(estimate)
matrix EV[3,6] = r(se)


regress writing_abortionNST c.abs_votes_abortion_inw2LPP3N##i.method  i.block, 
lincom c.abs_votes_abortion_inw2LPP3N + 1.method#c.abs_votes_abortion_inw2LPP3N , level(90)
matrix EV[4,1] = r(estimate)
matrix EV[4,2] = r(se)
lincom c.abs_votes_abortion_inw2LPP3N + 2.method#c.abs_votes_abortion_inw2LPP3N , level(90)
matrix EV[4,3] = r(estimate)
matrix EV[4,4] = r(se)
lincom c.abs_votes_abortion_inw2LPP3N + 3.method#c.abs_votes_abortion_inw2LPP3N , level(90)
matrix EV[4,5] = r(estimate)
matrix EV[4,6] = r(se)


regress punish_FaST c.diffLPP3N##i.method  i.block
lincom c.diffLPP3N + 1.method#c.diffLPP3N , level(90)
matrix EV[5,1] = r(estimate)
matrix EV[5,2] = r(se)
lincom c.diffLPP3N + 2.method#c.diffLPP3N , level(90)
matrix EV[5,3] = r(estimate)
matrix EV[5,4] = r(se)
lincom c.diffLPP3N + 3.method#c.diffLPP3N , level(90)
matrix EV[5,5] = r(estimate)
matrix EV[5,6] = r(se)


regress proportionST c.diffLPP3N##i.method i.block
lincom c.diffLPP3N + 1.method#c.diffLPP3N , level(90)
matrix EV[6,1] = r(estimate)
matrix EV[6,2] = r(se)
lincom c.diffLPP3N + 2.method#c.diffLPP3N , level(90)
matrix EV[6,3] = r(estimate)
matrix EV[6,4] = r(se)
lincom c.diffLPP3N + 3.method#c.diffLPP3N , level(90)
matrix EV[6,5] = r(estimate)
matrix EV[6,6] = r(se)

putexcel set  "$pathtemp/EV", replace
putexcel A1=matrix(EV) 



**** code for the figure 


preserve

clear all

cd "$pathtemp"
import excel EV

gen topic = _n


rename A est1
rename B se1
rename C est2
rename D se2
rename E est3
rename F se3

reshape long est se, i(topic) j(method)    

sort topic method
gen order = _n
gen lb = est - 1.96*se
gen ub = est + 1.96*se


tw (scatter est order,  legend(off) ylabel(0(0.2)2.2) yline(0, lc(black) lstyle(gs15)) ///
text(2.2 1.5 "Gun", place(e)) ///
text(2.2 3.9 "Immigration", place(e)) ///
text(2.2 7.2 "Minimum", place(e)) ///
text(2.0 7.4 "Wage", place(e)) ///
text(2.2 10 "Abortion", place(e)) ///
text(2.2 12.5 "DG punish (1)", place(e)) ///
text(2.2 15.8 "DG punish (2)", place(e)) ///
xlabel(1 "Likert" 2 "Likert +" 3 "QVSR" 4 " " 5 " " 6 " " 7 "Likert" 8 "Likert +" 9 "QVSR" ///
10 " " 11 " " 12 " " 13 "Likert" 14 "Likert +" 15 "QVSR" 16 " " 17 " " 18 " " , angle(45)labsize(small) ) ///
xtitle(" ", size(zero))) ///
(rcap lb ub order, xline(3.5) xline(6.5) xline(9.5) xline(12.5) xline(15.5))

cd "$pathfig"
graph export "FigD1.pdf", replace 

restore

****************************
* OUTPUT FIG D1            *
* SEE "FigD1.pdf" IN "FIG" *
****************************


*----- 
*-------------------------------
*---  E. Alternative Approaches to Likert+ -- Table E8


use "$pathout/dataset_final.dta", replace

*** recode variables to help with table output 
rename sex Gender
recode Gender (1 = 0) (2= 1)

rename wall_IP wall_in_IP
rename abortion_IP abortion_in_IP

*** higher value = liberal position
gen wall_inLp = (-1 * wallLp)
gen abortion_inLp = (-1 * abortionLp)

*** take abs value of the first item in Likert + for letter writing task
gen abs_abortion_in = abs(abortionLp)
gen abs_minW = abs(minWLp)

gen Don_gun = don_C_gunST 
gen Don_immi = don_C_wall_inST 
gen Letter_abor = writing_abortionNST 
gen Letter_minW = writing_minWNST 
gen Prox_childB = child2 


*** coef for Table E8 + values for "Y-hat linear"
qui reg Don_gun c.gunLp##c.gun_IP if method == 2
est store inter_gun
predict YH_gun

qui reg Don_immi c.wall_inLp##c.wall_in_IP if method == 2
est store inter_wall_in
predict YH_wall_in

qui reg Letter_abor c.abs_abortion_in##c.abortion_in_IP if method == 2
est store inter_abortion_in
predict YH_abortion_in

qui reg Letter_minW c.abs_minW##c.minW_IP if method == 2
est store inter_minW
predict YH_minW

qui reg Gender c.genderLp##c.gender_IP if method == 2
est store inter_gender
predict YH_gender

qui reg Prox_childB c.paidLLp##c.paidL_IP if method == 2
est store inter_paidL
predict YH_paidL


cd "$pathtab"


esttab inter_gun inter_wall_in inter_abortion_in inter_minW inter_gender inter_paidL ///
using Yhat.tex, style(tex) cells(b(star fmt(2)) se(par(( )) fmt(2))) ///
starlevels(+ 0.10 * .05 ** .01 *** .001) ///
ar2 varlabels(_cons cons ///
gunLp Likert ///
gun_IP Issue_importance ///
c.gunLp#c.gun_IP Interaction ///
wall_inLp Likert ///
wall_in_IP Issue_importance ///
c.wall_inLp#c.wall_in_IP Interaction ///
abs_abortion_in Likert_abs ///
abortion_in_IP Issue_importance ///
c.abs_abortion_in#c.abortion_in_IP Interaction ///
abs_minW Likert_abs ///
minW_IP Issue_importance ///
c.abs_minW#c.minW_IP Interaction ///
genderLp Likert ///
gender_IP Issue_importance ///
c.genderLp#c.gender_IP Interaction ///
paidLLp Likert ///
paidL_IP Issue_importance ///
c.paidLLp#c.paidL_IP Interaction ) replace


**********************************************************
* OUTPUT TAB E8                           				 *
* PLEASE RUN CORRESPONDING LATEX FILE AVAILABLE IN "TAB" *
**********************************************************


*----- 
*-------------------------------
*---  E. Alternative Approaches to Likert+ -- Figure E2




*** values for "Y-hat quadratic"
qui reg don_C_gunST c.gunLp##c.gun_IP##c.gun_IP if method == 2
predict YH_gun2

qui reg don_C_wall_inST c.wall_inLp##c.wall_in_IP##c.wall_in_IP if method == 2
predict YH_wall_in2

qui reg writing_abortionNST c.abs_abortion_in##c.abortion_in_I##c.abortion_in_IP if method == 2
predict YH_abortion_in2

qui reg writing_minWNST c.abs_minW##c.minW_IP##c.minW_IP if method == 2
predict YH_minW2

qui reg Gender c.genderLp##c.gender_IP##c.gender_IP if method == 2
predict YH_gender2

qui reg child2 c.paidLLp##c.paidL_IP##c.paidL_IP if method == 2
predict YH_paidL2


gen diffYH = (YH_gun - YH_wall_in)
gen diffYH2 = (YH_gun2 - YH_wall_in2)



** nornalize Y-had lineaire and quadratic

local issues  gun wall_in abortion_in minW
foreach var in `issues' {
gen YH_`var'N = .
egen min`var' = min(YH_`var') if method == 2
egen max`var' = max(YH_`var') if method == 2
replace YH_`var'N  =(YH_`var'  - (min`var')) / (max`var' - (min`var')) if method == 2
drop max`var' min`var'
gen YH_`var'2N = .
egen min`var' = min(YH_`var'2) if method == 2
egen max`var' = max(YH_`var'2) if method == 2
replace YH_`var'2N  =(YH_`var'  - (min`var')) / (max`var' - (min`var')) if method == 2
drop max`var' min`var'
}


local issues  YH YH2
foreach var in `issues' {
gen diff`var'N = .
egen min`var' = min(diff`var') if method == 2
egen max`var' = max(diff`var') if method == 2
replace diff`var'N  =(diff`var'  - (min`var')) / (max`var' - (min`var')) if method == 2
drop max`var' min`var'
}




matrix EV = J(6,6,0)
matrix colnames EV = "ImpO" " " "Add" " " "Multi" " " 
matrix rownames EV = "Gun-related Donations" ///
"Immigration-related Donations" ///
"Minimum Wage-related Writing" /// 
"Abortion-related Writing" ///
"Punish abs" ///
"Punish proportion"


regress don_C_gunST c.votes_gunw1N i.block if method == 2
lincom c.votes_gunw1N 
matrix EV[1,1] = r(estimate)
matrix EV[1,2] = r(se)
regress don_C_gunST c.votes_gunw1LPP2N i.block if method == 2
lincom c.votes_gunw1LPP2N 
matrix EV[1,3] = r(estimate)
matrix EV[1,4] = r(se)
regress don_C_gunST c.votes_gunw1LPP3N i.block if method == 2
lincom c.votes_gunw1LPP3N 
matrix EV[1,5] = r(estimate)
matrix EV[1,6] = r(se)


regress don_C_wall_inST c.votes_wall_inw1N i.block if method == 2
lincom c.votes_wall_inw1N 
matrix EV[2,1] = r(estimate)
matrix EV[2,2] = r(se)
regress don_C_wall_inST c.votes_wall_inw1LPP2N i.block if method == 2
lincom c.votes_wall_inw1LPP2N 
matrix EV[2,3] = r(estimate)
matrix EV[2,4] = r(se)
regress don_C_wall_inST c.votes_wall_inw1LPP3N i.block if method == 2
lincom c.votes_wall_inw1LPP3N 
matrix EV[2,5] = r(estimate)
matrix EV[2,6] = r(se)


regress writing_minWNST c.abs_votes_minWw1N i.block if method == 2
lincom c.abs_votes_minWw1N 
matrix EV[3,1] = r(estimate)
matrix EV[3,2] = r(se)
regress writing_minWNST c.abs_votes_minWw1LPP2N i.block if method == 2
lincom c.abs_votes_minWw1LPP2N 
matrix EV[3,3] = r(estimate)
matrix EV[3,4] = r(se)
regress writing_minWNST c.abs_votes_minWw1LPP3N i.block if method == 2
lincom c.abs_votes_minWw1LPP3N 
matrix EV[3,5] = r(estimate)
matrix EV[3,6] = r(se)


regress writing_abortionNST c.abs_votes_abortion_inw1N i.block if method == 2
lincom c.abs_votes_abortion_inw1N 
matrix EV[4,1] = r(estimate)
matrix EV[4,2] = r(se)
regress writing_abortionNST c.abs_votes_abortion_inw1LPP2N i.block if method == 2
lincom c.abs_votes_abortion_inw1LPP2N 
matrix EV[4,3] = r(estimate)
matrix EV[4,4] = r(se)
regress writing_abortionNST c.abs_votes_abortion_inw1LPP3N i.block if method == 2
lincom c.abs_votes_abortion_inw1LPP3N 
matrix EV[4,5] = r(estimate)
matrix EV[4,6] = r(se)



regress punish_FaST c.diffN  i.block if method == 2
lincom c.diffN 
matrix EV[5,1] = r(estimate)
matrix EV[5,2] = r(se)
regress punish_FaST c.diffLPP2N  i.block if method == 2
lincom c.diffLPP2N
matrix EV[5,3] = r(estimate)
matrix EV[5,4] = r(se)
regress punish_FaST c.diffLPP3N  i.block if method == 2
lincom c.diffLPP3N
matrix EV[5,5] = r(estimate)
matrix EV[5,6] = r(se)


regress proportionST c.diffN  i.block if method == 2
lincom c.diffN 
matrix EV[6,1] = r(estimate)
matrix EV[6,2] = r(se)
regress proportionST c.diffLPP2N  i.block if method == 2
lincom c.diffLPP2N
matrix EV[6,3] = r(estimate)
matrix EV[6,4] = r(se)
regress proportionST c.diffLPP3N  i.block if method == 2
lincom c.diffLPP3N
matrix EV[6,5] = r(estimate)
matrix EV[6,6] = r(se)




cd "$pathtemp"

putexcel set  "$pathtemp/EV", replace
putexcel A1=matrix(EV) 



preserve

clear all

cd "$pathtemp"
import excel EV

gen topic = _n


rename A est1
rename B se1
rename C est2
rename D se2
rename E est3
rename F se3

reshape long est se, i(topic) j(method)    

sort topic method
gen order = _n
gen lb = est - 1.96*se
gen ub = est + 1.96*se


tw (scatter est order,  legend(off) ylabel(0(0.2)2.2) yline(0, lc(black) lstyle(gs15)) ///
text(2.2 1.5 "Gun", place(e)) ///
text(2.2 3.9 "Immigration", place(e)) ///
text(2.2 7.2 "Minimum", place(e)) ///
text(2.0 7.4 "Wage", place(e)) ///
text(2.2 10 "Abortion", place(e)) ///
text(2.2 12.5 "DG punish (1)", place(e)) ///
text(2.2 15.8 "DG punish (2)", place(e)) ///
xlabel(1 "ImpO" 2 "Add" 3 "Multi" 4 " " 5 " " 6 " " 7 "ImpO" 8 "Add" 9 "Multi" ///
10 " " 11 " " 12 " " 13 "ImpO" 14 "Add" 15 "Multi" 16 " " 17 " " 18 " " , angle(45)labsize(small) ) ///
xtitle(" ", size(zero))) ///
(rcap lb ub order, xline(3.5) xline(6.5) xline(9.5) xline(12.5) xline(15.5))

cd "$pathfig"
graph export "FigE2_top.pdf", replace 

restore 




matrix EV2 = J(6,6,0)
matrix colnames EV2 = "YHL" " " "YHQ" " " "Multi" " " 
matrix rownames EV2 = "Gun-related Donations" ///
"Immigration-related Donations" ///
"Minimum Wage-related Writing" /// 
"Abortion-related Writing" ///
"Punish abs" ///
"Punish proportion"


regress don_C_gunST c.YH_gunN i.block if method == 2
lincom c.YH_gunN
matrix EV2[1,1] = r(estimate)
matrix EV2[1,2] = r(se)
regress don_C_gunST c.YH_gun2N i.block if method == 2
lincom c.YH_gun2N
matrix EV2[1,3] = r(estimate)
matrix EV2[1,4] = r(se)
regress don_C_gunST c.votes_gunw1LPP3N i.block if method == 2
lincom c.votes_gunw1LPP3N 
matrix EV2[1,5] = r(estimate)
matrix EV2[1,6] = r(se)


regress don_C_wall_inST c.YH_wall_inN i.block if method == 2
lincom c.YH_wall_inN
matrix EV2[2,1] = r(estimate)
matrix EV2[2,2] = r(se)
regress don_C_wall_inST c.YH_wall_in2N i.block if method == 2
lincom c.YH_wall_in2N 
matrix EV2[2,3] = r(estimate)
matrix EV2[2,4] = r(se)
regress don_C_wall_inST c.votes_wall_inw1LPP3N i.block if method == 2
lincom c.votes_wall_inw1LPP3N 
matrix EV2[2,5] = r(estimate)
matrix EV2[2,6] = r(se)

regress writing_minWNST c.YH_minWN i.block if method == 2
lincom c.YH_minWN
matrix EV2[3,1] = r(estimate)
matrix EV2[3,2] = r(se)
regress writing_minWNST c.YH_minW2N i.block if method == 2
lincom c.YH_minW2N
matrix EV2[3,3] = r(estimate)
matrix EV2[3,4] = r(se)
regress writing_minWNST c.abs_votes_minWw1LPP3N i.block if method == 2
lincom c.abs_votes_minWw1LPP3N 
matrix EV2[3,5] = r(estimate)
matrix EV2[3,6] = r(se)


regress writing_abortionNST c.YH_abortion_inN i.block if method == 2
lincom c.YH_abortion_inN
matrix EV2[4,1] = r(estimate)
matrix EV2[4,2] = r(se)
regress writing_abortionNST c.YH_abortion_in2N i.block if method == 2
lincom c.YH_abortion_in2N 
matrix EV2[4,3] = r(estimate)
matrix EV2[4,4] = r(se)
regress writing_abortionNST c.abs_votes_abortion_inw1LPP3N i.block if method == 2
lincom c.abs_votes_abortion_inw1LPP3N 
matrix EV2[4,5] = r(estimate)
matrix EV2[4,6] = r(se)


regress punish_FaST c.diffYHN  i.block if method == 2
lincom c.diffYHN 
matrix EV2[5,1] = r(estimate)
matrix EV2[5,2] = r(se)
regress punish_FaST c.diffYH2N  i.block if method == 2
lincom c.diffYH2N
matrix EV2[5,3] = r(estimate)
matrix EV2[5,4] = r(se)
regress punish_FaST c.diffLPP3N  i.block if method == 2
lincom c.diffLPP3N
matrix EV2[5,5] = r(estimate)
matrix EV2[5,6] = r(se)


regress proportionST c.diffYHN  i.block if method == 2
lincom c.diffYHN 
matrix EV2[6,1] = r(estimate)
matrix EV2[6,2] = r(se)
regress proportionST c.diffYH2N  i.block if method == 2
lincom c.diffYH2N
matrix EV2[6,3] = r(estimate)
matrix EV2[6,4] = r(se)
regress proportionST c.diffLPP3N  i.block if method == 2
lincom c.diffLPP3N
matrix EV2[6,5] = r(estimate)
matrix EV2[6,6] = r(se)





cd "$pathtemp"


putexcel set  "$pathtemp/EV2", replace
putexcel A1=matrix(EV2) 



**** code for the figure 


preserve

clear all

cd "$pathtemp"
import excel EV2

gen topic = _n


rename A est1
rename B se1
rename C est2
rename D se2
rename E est3
rename F se3

reshape long est se, i(topic) j(method)    

sort topic method
gen order = _n
gen lb = est - 1.96*se
gen ub = est + 1.96*se


tw (scatter est order,  legend(off) ylabel(0(0.2)2.2) yline(0, lc(black) lstyle(gs15)) ///
text(2.2 1.5 "Gun", place(e)) ///
text(2.2 3.9 "Immigration", place(e)) ///
text(2.2 7.2 "Minimum", place(e)) ///
text(2.0 7.4 "Wage", place(e)) ///
text(2.2 10 "Abortion", place(e)) ///
text(2.2 12.5 "DG punish (1)", place(e)) ///
text(2.2 15.8 "DG punish (2)", place(e)) ///
xlabel(1 "YHL" 2 "YHQ" 3 "Multi" 4 " " 5 " " 6 " " 7 "YHL" 8 "YHQ" 9 "Multi" ///
10 " " 11 " " 12 " " 13 "YHL" 14 "YHQ" 15 "Multi" 16 " " 17 " " 18 " " , angle(45)labsize(small) ) ///
xtitle(" ", size(zero))) ///
(rcap lb ub order, xline(3.5) xline(6.5) xline(9.5) xline(12.5) xline(15.5))

cd "$pathfig"
graph export "FigE2_bot.pdf", replace 


restore 


**************************************************
* OUTPUT FIG E2                                  *
* SEE "FigE2_opt.pdf" & "FigE2_bot.pdf" IN "FIG" *
**************************************************




*----- 
*-------------------------------
*---  E. Alternative Approaches to Likert+ -- Figure E3




matrix EV3 = J(6,6,0)
matrix colnames EV3 = "Likert" " " "Likert + (YHQ)" " " "QVSR" " " 
matrix rownames EV3 = "Gun-related Donations" ///
"Immigration-related Donations" ///
"Minimum Wage-related Writing" /// 
"Abortion-related Writing" ///
"Punish abs" ///
"Punish proportion"


regress don_C_gunST c.votes_gunw1LPP3N##i.method i.block
lincom c.votes_gunw1LPP3N + 1.method#c.votes_gunw1LPP3N 
matrix EV3[1,1] = r(estimate)
matrix EV3[1,2] = r(se)
lincom c.votes_gunw1LPP3N + 3.method#c.votes_gunw1LPP3N 
matrix EV3[1,5] = r(estimate)
matrix EV3[1,6] = r(se)
regress don_C_gunST c.YH_gun2N i.block if method == 2
lincom c.YH_gun2N
matrix EV3[1,3] = r(estimate)
matrix EV3[1,4] = r(se)


regress don_C_wall_inST c.votes_wall_inw1LPP3N##i.method  i.block
lincom c.votes_wall_inw1LPP3N + 1.method#c.votes_wall_inw1LPP3N 
matrix EV3[2,1] = r(estimate)
matrix EV3[2,2] = r(se)
lincom c.votes_wall_inw1LPP3N + 3.method#c.votes_wall_inw1LPP3N 
matrix EV3[2,5] = r(estimate)
matrix EV3[2,6] = r(se)
regress don_C_wall_inST c.YH_wall_in2N i.block if method == 2
lincom c.YH_wall_in2N 
matrix EV3[2,3] = r(estimate)
matrix EV3[2,4] = r(se)


regress writing_minWNST c.abs_votes_minWw1LPP3N##i.method  i.block
lincom c.abs_votes_minWw1LPP3N + 1.method#c.abs_votes_minWw1LPP3N 
matrix EV3[3,1] = r(estimate)
matrix EV3[3,2] = r(se)
lincom c.abs_votes_minWw1LPP3N + 3.method#c.abs_votes_minWw1LPP3N 
matrix EV3[3,5] = r(estimate)
matrix EV3[3,6] = r(se)
regress writing_minWNST c.YH_minW2N i.block if method == 2
lincom c.YH_minW2N
matrix EV3[4,3] = r(estimate)
matrix EV3[4,4] = r(se)


regress writing_abortionNST c.abs_votes_abortion_inw1LPP3N##i.method  i.block, 
lincom c.abs_votes_abortion_inw1LPP3N + 1.method#c.abs_votes_abortion_inw1LPP3N 
matrix EV3[4,1] = r(estimate)
matrix EV3[4,2] = r(se)
lincom c.abs_votes_abortion_inw1LPP3N + 3.method#c.abs_votes_abortion_inw1LPP3N 
matrix EV3[4,5] = r(estimate)
matrix EV3[4,6] = r(se)
regress writing_abortionNST c.YH_abortion_in2N i.block if method == 2
lincom c.YH_abortion_in2N 
matrix EV3[3,3] = r(estimate)
matrix EV3[3,4] = r(se)


regress punish_FaST c.diffLPP3N##i.method  i.block
lincom c.diffLPP3N + 1.method#c.diffLPP3N 
matrix EV3[5,1] = r(estimate)
matrix EV3[5,2] = r(se)
lincom c.diffLPP3N + 3.method#c.diffLPP3N 
matrix EV3[5,5] = r(estimate)
matrix EV3[5,6] = r(se)
regress punish_FaST c.diffYH2N  i.block if method == 2
lincom c.diffYH2N
matrix EV3[5,3] = r(estimate)
matrix EV3[5,4] = r(se)


regress proportionST c.diffLPP3N##i.method i.block
lincom c.diffLPP3N + 1.method#c.diffLPP3N 
matrix EV3[6,1] = r(estimate)
matrix EV3[6,2] = r(se)
lincom c.diffLPP3N + 3.method#c.diffLPP3N 
matrix EV3[6,5] = r(estimate)
matrix EV3[6,6] = r(se)
regress proportionST c.diffYH2N  i.block if method == 2
lincom c.diffYH2N
matrix EV3[6,3] = r(estimate)
matrix EV3[6,4] = r(se)


cd "$pathtemp"


putexcel set  "$pathtemp/EV3", replace
putexcel A1=matrix(EV3) 




**** code for the figure 


preserve

clear all

cd "$pathtemp"
import excel EV3

gen topic = _n


rename A est1
rename B se1
rename C est2
rename D se2
rename E est3
rename F se3

reshape long est se, i(topic) j(method)    

sort topic method
gen order = _n
gen lb = est - 1.96*se
gen ub = est + 1.96*se


tw (scatter est order,  legend(off) ylabel(0(0.2)2.2) yline(0, lc(black) lstyle(gs15)) ///
text(2.2 1.5 "Gun", place(e)) ///
text(2.2 3.9 "Immigration", place(e)) ///
text(2.2 7.2 "Minimum", place(e)) ///
text(2.0 7.4 "Wage", place(e)) ///
text(2.2 10 "Abortion", place(e)) ///
text(2.2 12.5 "DG punish (1)", place(e)) ///
text(2.2 15.8 "DG punish (2)", place(e)) ///
xlabel(1 "Likert" 2 "Likert +" 3 "QVSR" 4 " " 5 " " 6 " " 7 "Likert" 8 "Likert +" 9 "QVSR" ///
10 " " 11 " " 12 " " 13 "Likert" 14 "Likert +" 15 "QVSR" 16 " " 17 " " 18 " " , angle(45)labsize(small) ) ///
xtitle(" ", size(zero))) ///
(rcap lb ub order, xline(3.5) xline(6.5) xline(9.5) xline(12.5) xline(15.5))

cd "$pathfig"
graph export "FigE3.pdf", replace 

restore


erase "$pathtemp/EV.xlsx"
erase "$pathtemp/EV2.xlsx"
erase "$pathtemp/EV3.xlsx"



*****************************
* OUTPUT FIG E3             *
* SEE "FigE3t.pdf" IN "FIG" *
*****************************





*----- 
*-------------------------------
*---  F. Table F9


preserve

matrix EN = J(10,3,0)
matrix colnames EN = "Likert"  "Likert +"  "QVSR" 
matrix rownames EN = "Same sex right to adopt" ///
"Make it difficult to buy gun" ///
"Wall on the US Border" ///
"Paid leave " ///
"Preferential hiring of blacks" ///
"Pay women and men the same" ///
"Minimum wage to 15 an hour" ///
"Ban on abortion" ///
"Cap on federal spending" ///
"Regulation for environment"




local variables gay gun wall paidL AA gender minW abortion deficit enviro 
foreach var in `variables' {
entropyetc votes_`var'w1 if method == 1 , list gen(2=entro1_`var')
}

local variables gay gun wall paidL AA gender minW abortion deficit enviro 
foreach var in `variables' {
entropyetc votes_`var'w1 if method == 2 , list gen(2=entro2_`var')
}

local variables gay gun wall paidL AA gender minW abortion deficit enviro 
foreach var in `variables' {
entropyetc votes_`var'w1 if method == 3 , list gen(2=entro3_`var')
}

collapse (mean) entro1_gay-entro3_enviro
mkmat entro1_gay-entro3_enviro, mat(entropy)
	
	
local i=1
while `i' <=10 {
matrix EN[`i',1] = entropy[1, `i']	
local i = `i'+1	
}

	
local i=11
while `i' <=20 {
local j= `i'-10
matrix EN[`j',2] = entropy[1, `i']	
local i = `i'+1
}


local i=21
while `i' <=30 {
local j= `i'-20
matrix EN[`j',3] = entropy[1, `i']	
local i = `i'+1
}

cd "$pathtab"

esttab matrix(EN, fmt("2 2")) using entropy.tex, replace ///
title(Entropy Scores \label{entropy}) 

restore


**********************************************************
* OUTPUT TAB F9                         				 *
* PLEASE RUN CORRESPONDING LATEX FILE AVAILABLE IN "TAB" *
**********************************************************



*----- 
*-------------------------------
*---  F2 Scatter Plots and Histograms 



cd "$pathtemp"


local issues LPP3
foreach j in `issues' {

egen mean_wall_inL_`j' = mean(don_C_wall_in) if method == 1 , by(votes_wall_inw1N)
egen mean_wall_inLp_`j' = mean(don_C_wall_in) if method == 2 , by(votes_wall_inw1`j'N)
egen mean_wall_inQV_`j' = mean(don_C_wall_in) if method == 3 , by(votes_wall_inw1N)

egen count_wall_in_`j' = count(votes_wall_inw1`j'N), by(method votes_wall_inw1`j'N)
} 


*** drop ouliers for LPP3

local issues LPP3
foreach j in `issues' {
	
preserve

drop if mean_wall_inLp_`j' < -40

tw (lfitci don_C_wall_in votes_wall_inw1`j'N if method == 2,  level(95) clp(dash_dot) clc(black) yline(-20) yline(20)) ///
(scatter mean_wall_inLp_`j' votes_wall_inw1`j'N if method == 2 [w=count_wall_in_`j'],  mc(black)  msymbol(oh) ///
ylabel(-40(20)40 , angle(horizontal)labsize(medsmall)) yline(0) xlabel(0(0.1)1, angle(horizontal)labsize(medsmall)) ///
ytitle("Donation (amount)", size(medsmall)) xtitle("", size(medsmall)) ///
title("Likert+")  legend(off) )
graph save "wall_in_fig2`j'.gph", replace 

restore


}


tw (lfitci don_C_wall_in votes_wall_inw1N if method == 1,  level(95) clp(shortdash) clc(black) yline(-20) yline(20)) ///
(scatter mean_wall_inL_LPP3 votes_wall_inw1N if method == 1 [w=count_wall_in_LPP3],  mc(black)  msymbol(oh) ///
ylabel(-40(20)40 , angle(horizontal)labsize(medsmall)) yline(0) xlabel(0(0.1)1, angle(horizontal)labsize(medsmall)) ///
ytitle("", size(medsmall)) xtitle("", size(medsmall)) ///
title("Likert")  legend(off) )
graph save "wall_in_fig2L.gph", replace 


tw (lfitci don_C_wall_in votes_wall_inw1N if method == 3,  level(95) clp(shortdash) clc(black) yline(-20) yline(20)) ///
(scatter mean_wall_inQV_LPP3 votes_wall_inw1N if method == 3 [w=count_wall_in_LPP3],  mc(black)  msymbol(oh) ///
ylabel(-40(20)40 , angle(horizontal)labsize(medsmall)) yline(0) xlabel(0(0.1)1, angle(horizontal)labsize(medsmall)) ///
ytitle("", size(medsmall)) xtitle("", size(medsmall)) ///
title("QVSR")  legend(off) )
graph save "wall_in_fig2QV.gph", replace 


***---  bottom figures

local issues LPP3
foreach j in `issues' {
		
gr tw (hist votes_wall_inw1`j'N if  method == 2, frac ///
discrete bfcolor(teal)  blcolor(white) title("")) ,  leg(off)  ///
graphr(fc(white) lc(white) ifc(white) ilc(white)) title("", size(medium)) yti("") xti("") ///
ysc(range(0 .5)) ylab(0(.1).5)	///
xsc(range(0 1)) xlab(0(0.1)1) fysize(20) ///
ytitle("Density", size(medsmall)) 
graph save "wall_in`j'w1N.gph", replace 

}



gr tw (hist votes_wall_inw1N if  method == 1, frac ///
discrete bfcolor(teal)  blcolor(white) title("")) ,  leg(off)  ///
graphr(fc(white) lc(white) ifc(white) ilc(white)) title("", size(medium)) yti("") xti("") ///
ysc(range(0 .5)) ylab(0(.1).5)	///
xsc(range(0 1)) xlab(0(0.1)1) fysize(20) 
graph save "wall_inLw1N.gph", replace 
	
gr tw (hist votes_wall_inw1N if  method == 3, frac ///
discrete bfcolor(teal)  blcolor(white) title("")) ,  leg(off)  ///
graphr(fc(white) lc(white) ifc(white) ilc(white)) title("", size(medium)) yti("") xti("") ///
ysc(range(0 .5)) ylab(0(.1).5)	///
xsc(range(0 1)) xlab(0(0.1)1) fysize(20) 
graph save "wall_inQVw1N.gph", replace 



cd "$pathtemp"

graph combine  "wall_in_fig2LPP3.gph"  "wall_in_fig2L.gph" "wall_in_fig2QV.gph"  ///
 "wall_inLPP3w1N.gph" "wall_inLw1N.gph" "wall_inQVw1N.gph" , ///
col(3) title("Immigration Donations and Opposition to Border Wall", size(med)) 
graph export "$pathfig/AppendixF2_1.pdf", replace

cd "$pathtemp"

erase "wall_in_fig2LPP3.gph"  
erase "wall_in_fig2L.gph" 
erase "wall_in_fig2QV.gph"  
erase "wall_inLPP3w1N.gph" 
erase "wall_inLw1N.gph" 
erase "wall_inQVw1N.gph"

*** abortion letter wrriting 



cd "$pathtemp"


local issues LPP3
foreach j in `issues' {

egen mean_abortionL_`j' = mean(writing_abortionNST ) if method == 1 , by(votes_abortionw1N)
egen mean_abortionLp_`j' = mean(writing_abortionNST ) if method == 2 , by(votes_abortionw1`j'N)
egen mean_abortionQV_`j' = mean(writing_abortionNST ) if method == 3 , by(votes_abortionw1N)

egen count_abortion_`j' = count(votes_abortionw1`j'N), by(method votes_abortionw1`j'N)
} 


local issues LPP3
foreach j in `issues' {
	
preserve

tw (qfitci writing_abortionNST votes_abortionw1`j'N if method == 2,  level(95) clp(dash_dot) clc(black) yline(-0.4) yline(0.4)) ///
(scatter mean_abortionLp_`j' votes_abortionw1`j'N if method == 2 [w=count_abortion_`j'],  mc(black)  msymbol(oh) ///
ylabel(-0.8(0.2)1.8  , angle(horizontal)labsize(medsmall)) yline(0) xlabel(0(0.1)1, angle(horizontal)labsize(medsmall)) ///
ytitle("Writing length (stand.)", size(medsmall)) xtitle("", size(medsmall)) ///
title("Likert +")  legend(off) )
graph save "abortion_fig2`j'.gph", replace 

restore


}


tw (qfitci writing_abortionNST votes_abortionw1N if method == 1,  level(95) clp(shortdash) clc(black) yline(-0.4) yline(0.4)) ///
(scatter mean_abortionL_LPP3 votes_abortionw1N if method == 1 [w=count_abortion_LPP3],  mc(black)  msymbol(oh) ///
ylabel(-0.8(0.2)1.8 , angle(horizontal)labsize(medsmall)) yline(0) xlabel(0(0.1)1, angle(horizontal)labsize(medsmall)) ///
ytitle("", size(medsmall)) xtitle("", size(medsmall)) ///
title("Likert")  legend(off) )
graph save "abortion_fig2L.gph", replace 


tw (qfitci writing_abortionNST votes_abortionw1N if method == 3,  level(95) clp(shortdash) clc(black) yline(-0.4) yline(0.4)) ///
(scatter mean_abortionQV_LPP3 votes_abortionw1N if method == 3 [w=count_abortion_LPP3],  mc(black)  msymbol(oh) ///
ylabel(-0.8(0.2)1.8 , angle(horizontal)labsize(medsmall)) yline(0) xlabel(0(0.1)1, angle(horizontal)labsize(medsmall)) ///
ytitle("", size(medsmall)) xtitle("", size(medsmall)) ///
title("QVSR")  legend(off) )
graph save "abortion_fig2QV.gph", replace 


***---  bottom figures

local issues LPP3
foreach j in `issues' {
		
gr tw (hist votes_abortionw1`j'N if  method == 2, frac ///
discrete bfcolor(teal)  blcolor(white) title("")) ,  leg(off)  ///
graphr(fc(white) lc(white) ifc(white) ilc(white)) title("", size(medium)) yti("") xti("") ///
ysc(range(0 .5)) ylab(0(.1).5)	///
xsc(range(0 1)) xlab(0(0.1)1) fysize(20) ///
ytitle("Density", size(medsmall)) 
graph save "abortion`j'w1N.gph", replace 

}



gr tw (hist votes_abortionw1N if  method == 1, frac ///
discrete bfcolor(teal)  blcolor(white) title("")) ,  leg(off)  ///
graphr(fc(white) lc(white) ifc(white) ilc(white)) title("", size(medium)) yti("") xti("") ///
ysc(range(0 .5)) ylab(0(.1).5)	///
xsc(range(0 1)) xlab(0(0.1)1) fysize(20) 
graph save "abortionLw1N.gph", replace 
	
gr tw (hist votes_abortionw1N if  method == 3, frac ///
discrete bfcolor(teal)  blcolor(white) title("")) ,  leg(off)  ///
graphr(fc(white) lc(white) ifc(white) ilc(white)) title("", size(medium)) yti("") xti("") ///
ysc(range(0 .5)) ylab(0(.1).5)	///
xsc(range(0 1)) xlab(0(0.1)1) fysize(20) 
graph save "abortionQVw1N.gph", replace 



cd "$pathtemp"

graph combine  "abortion_fig2LPP3.gph"  "abortion_fig2L.gph" "abortion_fig2QV.gph"  ///
 "abortionLPP3w1N.gph" "abortionLw1N.gph" "abortionQVw1N.gph" , ///
col(3) title("Length of Writing: Abortion Bill and Support for Abortion", size(med)) 
graph export "$pathfig/AppendixF2_2.pdf", replace

erase "abortion_fig2LPP3.gph"
erase "abortion_fig2L.gph"
erase "abortion_fig2QV.gph"
erase "abortionLPP3w1N.gph" 
erase "abortionLw1N.gph" 
erase "abortionQVw1N.gph"


*** min wage letter wrriting 




cd "$pathtemp"


local issues LPP3
foreach j in `issues' {

egen mean_minWL_`j' = mean(writing_minWNST ) if method == 1 , by(votes_minWw1N)
egen mean_minWLp_`j' = mean(writing_minWNST ) if method == 2 , by(votes_minWw1`j'N)
egen mean_minWQV_`j' = mean(writing_minWNST ) if method == 3 , by(votes_minWw1N)

egen count_minW_`j' = count(votes_minWw1`j'N), by(method votes_minWw1`j'N)
} 



local issues LPP3
foreach j in `issues' {
	
preserve

tw (qfitci writing_minWNST votes_minWw1`j'N if method == 2,  level(95) clp(dash_dot) clc(black) yline(-0.4) yline(0.4)) ///
(scatter mean_minWLp_`j' votes_minWw1`j'N if method == 2 [w=count_minW_`j'],  mc(black)  msymbol(oh) ///
ylabel(-0.8(0.2)1  , angle(horizontal)labsize(medsmall)) yline(0) xlabel(0(0.1)1, angle(horizontal)labsize(medsmall)) ///
ytitle("Writing length (stand.)", size(medsmall)) xtitle("", size(medsmall)) ///
title("Likert +")  legend(off) )
graph save "minW_fig2`j'.gph", replace 

restore


}


tw (qfitci writing_minWNST votes_minWw1N if method == 1,  level(95) clp(shortdash) clc(black) yline(-0.4) yline(0.4)) ///
(scatter mean_minWL_LPP3 votes_minWw1N if method == 1 [w=count_minW_LPP3],  mc(black)  msymbol(oh) ///
ylabel(-0.8(0.2)1 , angle(horizontal)labsize(medsmall)) yline(0) xlabel(0(0.1)1, angle(horizontal)labsize(medsmall)) ///
ytitle("", size(medsmall)) xtitle("", size(medsmall)) ///
title("Likert")  legend(off) )
graph save "minW_fig2L.gph", replace 


tw (qfitci writing_minWNST votes_minWw1N if method == 3,  level(95) clp(shortdash) clc(black) yline(-0.4) yline(0.4)) ///
(scatter mean_minWQV_LPP3 votes_minWw1N if method == 3 [w=count_minW_LPP3],  mc(black)  msymbol(oh) ///
ylabel(-0.8(0.2)1 , angle(horizontal)labsize(medsmall)) yline(0) xlabel(0(0.1)1, angle(horizontal)labsize(medsmall)) ///
ytitle("", size(medsmall)) xtitle("", size(medsmall)) ///
title("QVSR")  legend(off) )
graph save "minW_fig2QV.gph", replace 


***---  bottom figures

local issues LPP3
foreach j in `issues' {
		
gr tw (hist votes_minWw1`j'N if  method == 2, frac ///
discrete bfcolor(teal)  blcolor(white) title("")) ,  leg(off)  ///
graphr(fc(white) lc(white) ifc(white) ilc(white)) title("", size(medium)) yti("") xti("") ///
ysc(range(0 .5)) ylab(0(.1).5)	///
xsc(range(0 1)) xlab(0(0.1)1) fysize(20) ///
ytitle("Density", size(medsmall)) 
graph save "minW`j'w1N.gph", replace 

}



gr tw (hist votes_minWw1N if  method == 1, frac ///
discrete bfcolor(teal)  blcolor(white) title("")) ,  leg(off)  ///
graphr(fc(white) lc(white) ifc(white) ilc(white)) title("", size(medium)) yti("") xti("") ///
ysc(range(0 .5)) ylab(0(.1).5)	///
xsc(range(0 1)) xlab(0(0.1)1) fysize(20) 
graph save "minWLw1N.gph", replace 
	
gr tw (hist votes_minWw1N if  method == 3, frac ///
discrete bfcolor(teal)  blcolor(white) title("")) ,  leg(off)  ///
graphr(fc(white) lc(white) ifc(white) ilc(white)) title("", size(medium)) yti("") xti("") ///
ysc(range(0 .5)) ylab(0(.1).5)	///
xsc(range(0 1)) xlab(0(0.1)1) fysize(20) 
graph save "minWQVw1N.gph", replace 



cd "$pathtemp"

graph combine  "minW_fig2LPP3.gph"  "minW_fig2L.gph" "minW_fig2QV.gph"  ///
 "minWLPP3w1N.gph" "minWLw1N.gph" "minWQVw1N.gph" , ///
col(3) title("Length of Writing: minW Bill and Support for minW", size(med)) 
graph export "$pathfig/AppendixF2_3.pdf", replace

erase "minW_fig2LPP3.gph"  
erase "minW_fig2L.gph"
erase "minW_fig2QV.gph"  
erase "minWLPP3w1N.gph"
erase "minWLw1N.gph" 
erase "minWQVw1N.gph" 


*** punishment (1) punish_FaST 

cd "$pathtemp"


egen mean_punishL_LPP3 = mean(punish_FaST ) if method == 1 , by(diffLPP3N)
egen mean_punishLp_LPP3 = mean(punish_FaST ) if method == 2 , by(diffLPP3N)
egen mean_punishQV_LPP3 = mean(punish_FaST ) if method == 3 , by(diffLPP3N)

egen count_punish_LPP3 = count(diffLPP3N), by(method diffLPP3N)


tw (lfitci punish_FaST diffLPP3N if method == 2,  level(95) clp(dash_dot) clc(black) yline(-0.4) yline(0.4)) ///
(scatter mean_punishLp_LPP3 diffLPP3N if method == 2 [w=count_punish_LPP3],  mc(black)  msymbol(oh) ///
ylabel(-0.8(0.2)1  , angle(horizontal)labsize(medsmall)) yline(0) xlabel(0(0.1)1, angle(horizontal)labsize(medsmall)) ///
ytitle("Amount taken (stand.)", size(medsmall)) xtitle("", size(medsmall)) ///
title("Likert +")  legend(off) )
graph save "punish1_fig2LPP3.gph", replace 


tw (lfitci punish_FaST diffLPP3N if method == 1,  level(95) clp(shortdash) clc(black) yline(-0.4) yline(0.4)) ///
(scatter mean_punishL_LPP3 diffLPP3N if method == 1 [w=count_punish_LPP3],  mc(black)  msymbol(oh) ///
ylabel(-0.8(0.2)1 , angle(horizontal)labsize(medsmall)) yline(0) xlabel(0(0.1)1, angle(horizontal)labsize(medsmall)) ///
ytitle("", size(medsmall)) xtitle("", size(medsmall)) ///
title("Likert")  legend(off) )
graph save "punish1_fig2L.gph", replace 


tw (lfitci punish_FaST diffLPP3N if method == 3,  level(95) clp(shortdash) clc(black) yline(-0.4) yline(0.4)) ///
(scatter mean_punishQV_LPP3 diffLPP3N if method == 3 [w=count_punish_LPP3],  mc(black)  msymbol(oh) ///
ylabel(-0.8(0.2)1 , angle(horizontal)labsize(medsmall)) yline(0) xlabel(0(0.1)1, angle(horizontal)labsize(medsmall)) ///
ytitle("", size(medsmall)) xtitle("", size(medsmall)) ///
title("QVSR")  legend(off) )
graph save "punish1_fig2QV.gph", replace 


***---  bottom figures

		
gr tw (hist diffLPP3N if  method == 2, frac ///
discrete bfcolor(teal)  blcolor(white) title("")) ,  leg(off)  ///
graphr(fc(white) lc(white) ifc(white) ilc(white)) title("", size(medium)) yti("") xti("") ///
ysc(range(0 .5)) ylab(0(.1).5)	///
xsc(range(0 1)) xlab(0(0.1)1) fysize(20) ///
ytitle("Density", size(medsmall)) 
graph save "punishLPP3w1N.gph", replace 


gr tw (hist diffLPP3N if  method == 1, frac ///
discrete bfcolor(teal)  blcolor(white) title("")) ,  leg(off)  ///
graphr(fc(white) lc(white) ifc(white) ilc(white)) title("", size(medium)) yti("") xti("") ///
ysc(range(0 .5)) ylab(0(.1).5)	///
xsc(range(0 1)) xlab(0(0.1)1) fysize(20) 
graph save "punishLw1N.gph", replace 
	
gr tw (hist diffLPP3N if  method == 3, frac ///
discrete bfcolor(teal)  blcolor(white) title("")) ,  leg(off)  ///
graphr(fc(white) lc(white) ifc(white) ilc(white)) title("", size(medium)) yti("") xti("") ///
ysc(range(0 .5)) ylab(0(.1).5)	///
xsc(range(0 1)) xlab(0(0.1)1) fysize(20) 
graph save "punishQVw1N.gph", replace 

cd "$pathtemp"

graph combine  "punish1_fig2LPP3.gph"  "punish1_fig2L.gph" "punish1_fig2QV.gph"  ///
 "punishLPP3w1N.gph" "punishLw1N.gph" "punishQVw1N.gph" , ///
col(3) title("Amount Taken in DG and Difference Gun - Immi", size(med)) 
graph export "$pathfig/AppendixF2_4.pdf", replace

erase "punish1_fig2LPP3.gph"  
erase "punish1_fig2L.gph" 
erase "punish1_fig2QV.gph"  




*** punishment (2) proportionST 

cd "$pathtemp"


egen mean_punish2L_LPP3 = mean(proportionST) if method == 1 , by(diffLPP3N)
egen mean_punish2Lp_LPP3 = mean(proportionST) if method == 2 , by(diffLPP3N)
egen mean_punish2QV_LPP3 = mean(proportionST) if method == 3 , by(diffLPP3N)


tw (lfitci proportionST  diffLPP3N if method == 2,  level(95) clp(dash_dot) clc(black) yline(-0.4) yline(0.4)) ///
(scatter mean_punish2Lp_LPP3 diffLPP3N if method == 2 [w=count_punish_LPP3],  mc(black)  msymbol(oh) ///
ylabel(-1.8(0.2)1  , angle(horizontal)labsize(medsmall)) yline(0) xlabel(0(0.1)1, angle(horizontal)labsize(medsmall)) ///
ytitle("% taken (stand.)", size(medsmall)) xtitle("", size(medsmall)) ///
title("Likert +")  legend(off) )
graph save "punish2_fig2LPP3.gph", replace 


tw (lfitci proportionST  diffLPP3N if method == 1,  level(95) clp(shortdash) clc(black) yline(-0.4) yline(0.4)) ///
(scatter mean_punish2L_LPP3 diffLPP3N if method == 1 [w=count_punish_LPP3],  mc(black)  msymbol(oh) ///
ylabel(-1.8(0.2)1 , angle(horizontal)labsize(medsmall)) yline(0) xlabel(0(0.1)1, angle(horizontal)labsize(medsmall)) ///
ytitle("", size(medsmall)) xtitle("", size(medsmall)) ///
title("Likert")  legend(off) )
graph save "punish2_fig2L.gph", replace 


tw (lfitci proportionST  diffLPP3N if method == 3,  level(95) clp(shortdash) clc(black) yline(-0.4) yline(0.4)) ///
(scatter mean_punish2QV_LPP3 diffLPP3N if method == 3 [w=count_punish_LPP3],  mc(black)  msymbol(oh) ///
ylabel(-1.8(0.2)1 , angle(horizontal)labsize(medsmall)) yline(0) xlabel(0(0.1)1, angle(horizontal)labsize(medsmall)) ///
ytitle("", size(medsmall)) xtitle("", size(medsmall)) ///
title("QVSR")  legend(off) )
graph save "punish2_fig2QV.gph", replace 





cd "$pathtemp"

graph combine  "punish2_fig2LPP3.gph"  "punish2_fig2L.gph" "punish2_fig2QV.gph"  ///
 "punishLPP3w1N.gph" "punishLw1N.gph" "punishQVw1N.gph" , ///
col(3) title("Perc. Taken in DG and Difference Gun - Immi", size(med)) 
graph export "$pathfig/AppendixF2_5.pdf", replace

erase "punish2_fig2LPP3.gph"  
erase "punish2_fig2L.gph" 
erase "punish2_fig2QV.gph"  
erase "punishLPP3w1N.gph" 
erase "punishLw1N.gph" 
erase "punishQVw1N.gph"


**************************************************************
* OUTPUT APPENDIX F2                        				 *
* PLEASE  See "AppendixF2_1"  "AppendixF2_2"  "AppendixF2_3" *
* "AppendixF2_4"  "AppendixF2_5" IN "FIG"                    *
**************************************************************


*----- 
*-------------------------------
*---  Appendix G - Material Self-Interest - Figures 

******load dataset

use "$pathout/dataset_final.dta", replace 


recode sex (1 = 0) (2 =1), gen(Gender)
rename black Black
rename votes_AAw1LPP3N votes_Blackw1LPP3N
rename votes_gunw1LPP3N votes_gunOaw1LPP3N

*** see table in text for coding 
recode minW ( 1 2 = 1) (3 = 0)
recode gunOa (2 3 = 0) (4 = 1)

cd "$pathtemp"

local issues Black gunOa minW
foreach j in `issues' {
gr tw (hist votes_Blackw1LPP3N if  method == 2, frac ///
discrete bfcolor(teal)  blcolor(white) title("")) ,  leg(off)  ///
graphr(fc(white) lc(white) ifc(white) ilc(white)) title("", size(medium)) yti("") xti("") ///
ysc(range(0 .5)) ylab(0(.1).5)	///
xsc(range(0 1)) xlab(0(0.1)1) fysize(20) ///
ytitle("Density", size(medsmall)) 
graph save "`j'LPP3w1N.gph", replace 

gr tw (hist votes_Blackw1LPP3N if  method == 1, frac ///
discrete bfcolor(teal)  blcolor(white) title("")) ,  leg(off)  ///
graphr(fc(white) lc(white) ifc(white) ilc(white)) title("", size(medium)) yti("") xti("") ///
ysc(range(0 .5)) ylab(0(.1).5)	///
xsc(range(0 1)) xlab(0(0.1)1) fysize(20) 
graph save "`j'Lw1N.gph", replace 
	
gr tw (hist votes_Blackw1LPP3N if  method == 3, frac ///
discrete bfcolor(teal)  blcolor(white) title("")) ,  leg(off)  ///
graphr(fc(white) lc(white) ifc(white) ilc(white)) title("", size(medium)) yti("") xti("") ///
ysc(range(0 .5)) ylab(0(.1).5)	///
xsc(range(0 1)) xlab(0(0.1)1) fysize(20) 
graph save "`j'QVw1N.gph", replace 
}



local issues Black minW gunOa
foreach j in `issues' {

egen mean_`j'L_LPP3 = mean(`j') if method == 1 , by(votes_`j'w1LPP3N)
egen mean_`j'Lp_LPP3 = mean(`j') if method == 2 , by(votes_`j'w1LPP3N)
egen mean_`j'QV_LPP3 = mean(`j') if method == 3 , by(votes_`j'w1LPP3N)

egen count_`j'LPP3 = count(votes_`j'w1LPP3N), by(method votes_`j'w1LPP3N)

}


local issues Black minW gunOa
foreach j in `issues' {

tw (lfitci `j' votes_`j'w1LPP3N if method == 2,  level(95) clp(dash_dot) clc(black) ) ///
(scatter mean_`j'Lp_LPP3 votes_`j'w1LPP3N if method == 2 [w=count_`j'LPP3],  mc(black)  msymbol(oh) ///
ylabel(0(0.2)1  , angle(horizontal)labsize(medsmall)) yline(0) xlabel(0(0.1)1, angle(horizontal)labsize(medsmall)) ///
ytitle("Percent affected", size(medsmall)) xtitle("", size(medsmall)) ///
title("Likert +")  legend(off) )
graph save "`j'_fig4LPP3.gph", replace 


tw (lfitci `j' votes_`j'w1LPP3N if method == 1,  level(95) clp(dash_dot) clc(black) ) ///
(scatter mean_`j'L_LPP3 votes_`j'w1LPP3N if method == 1 [w=count_`j'LPP3],  mc(black)  msymbol(oh) ///
ylabel(0(0.2)1  , angle(horizontal)labsize(medsmall)) yline(0) xlabel(0(0.1)1, angle(horizontal)labsize(medsmall)) ///
ytitle("", size(medsmall)) xtitle("", size(medsmall)) ///
title("Likert")  legend(off) )
graph save "`j'_fig4L.gph", replace 


tw (lfitci `j' votes_`j'w1LPP3N if method == 3,  level(95) clp(dash_dot) clc(black) ) ///
(scatter mean_`j'QV_LPP3 votes_`j'w1LPP3N if method == 3 [w=count_`j'LPP3],  mc(black)  msymbol(oh) ///
ylabel(0(0.2)1  , angle(horizontal)labsize(medsmall)) yline(0) xlabel(0(0.1)1, angle(horizontal)labsize(medsmall)) ///
ytitle("", size(medsmall)) xtitle("", size(medsmall)) ///
title("QVSR")  legend(off) )
graph save "`j'_fig4QV.gph", replace 

}

cd "$pathtemp"



local issues  gunOa
foreach j in `issues' {
graph combine  "`j'_fig4LPP3.gph"  "`j'_fig4L.gph" "`j'_fig4QV.gph"  ///
"`j'LPP3w1N.gph" "`j'Lw1N.gph" "`j'QVw1N.gph" , ///
col(3) title("% Does NOT Own a Gun and Support for Gun Control", size(med)) 
graph export "$pathfig/AppendixG_1.pdf", replace
	
	
}

local issues Black 
foreach j in `issues' {
graph combine  "`j'_fig4LPP3.gph"  "`j'_fig4L.gph" "`j'_fig4QV.gph"  ///
"`j'LPP3w1N.gph" "`j'Lw1N.gph" "`j'QVw1N.gph" , ///
col(3) title("% Black and Support for Affirmative Action", size(med)) 
graph export "$pathfig/AppendixG_2.pdf", replace
	
	
}

local issues minW 
foreach j in `issues' {
graph combine  "`j'_fig4LPP3.gph"  "`j'_fig4L.gph" "`j'_fig4QV.gph"  ///
"`j'LPP3w1N.gph" "`j'Lw1N.gph" "`j'QVw1N.gph" , ///
col(3) title("% At or Close to Min Wage and Support for Min Wage Increase", size(med)) 
graph export "$pathfig/AppendixG_3.pdf", replace
	
	
}

** erase

local issues Black 
foreach j in `issues' {
cd "$pathtemp"
erase  "`j'_fig4LPP3.gph"  
erase "`j'_fig4L.gph" 
erase "`j'_fig4QV.gph"  
erase "`j'LPP3w1N.gph" 
erase "`j'Lw1N.gph" 
erase "`j'QVw1N.gph" 
	
}

local issues minW 
foreach j in `issues' {
erase  "`j'_fig4LPP3.gph" 
erase  "`j'_fig4L.gph" 
erase  "`j'_fig4QV.gph" 
erase  "`j'LPP3w1N.gph" 
erase  "`j'Lw1N.gph" 
erase  "`j'QVw1N.gph" 
}

local issues  gunOa
foreach j in `issues' {
erase  "`j'_fig4LPP3.gph" 
erase  "`j'_fig4L.gph" 
erase  "`j'_fig4QV.gph" 
erase  "`j'LPP3w1N.gph" 
erase  "`j'Lw1N.gph"
erase  "`j'QVw1N.gph" 
}


**************************************************************
* OUTPUT APPENDIX F2 Figures                  				 *
* PLEASE  See "AppendixG_1"  "AppendixG_2"  "AppendixG_3"    *
*  IN "FIG"                                                  *
**************************************************************




*----- 
*-------------------------------
*---  Appendix G - Material Self-Interest - Tab G11


******load dataset

use "$pathout/dataset_final.dta", replace 


recode sex (1 = 0) (2 =1), gen(Gender)
rename black Black
rename votes_AAw1LPP3N votes_Blackw1LPP3N
rename votes_gunw1LPP3N votes_gunOaw1LPP3N

*** see table in text for coding 
recode minW ( 1 2 = 1) (3 = 0)
recode gunOa (2 3 = 0) (4 = 1)



matrix EV_tabG11 = J(2,3,0)
matrix colnames EV_tabG11 = "QVSR vs Likert" "Likert+ vs Likert" "QVSR vs LIkert+" 
matrix rownames EV_tabG11 = "F test" "Prob > F "



preserve

drop if method == 2

recode method (1 = 0) (3 = 1)

qui sureg (Gender c.votes_genderw1LPP3N##i.method i.block) ///
(child2 c.votes_paidLw1LPP3N##i.method i.block) ///
(gunOa c.votes_gunOaw1LPP3N##i.method i.block) ///
(Black c.votes_Blackw1LPP3N##i.method i.block) ///
(minW c.votes_minWw1LPP3N##i.method i.block) /// 
 , small dfk coeflegend 
 estimates store SUREG_LQV



test _b[Gender:1.method#c.votes_genderw1LPP3N] + ///
_b[child2:1.method#c.votes_paidLw1LPP3N]+ ///
_b[gunOa:1.method#c.votes_gunOaw1LPP3N] + ///
_b[Black:1.method#c.votes_Blackw1LPP3N] + ///
_b[minW:1.method#c.votes_minWw1LPP3N] = 0 
matrix EV_tabG11[1,1] = r(F)
matrix EV_tabG11[2,1] = r(p)

restore


preserve

drop if method == 1

recode method (2 = 0) (3 = 1)

qui sureg (Gender c.votes_genderw1LPP3N##i.method i.block) ///
(child2 c.votes_paidLw1LPP3N##i.method i.block) ///
(gunOa c.votes_gunOaw1LPP3N##i.method i.block) ///
(Black c.votes_Blackw1LPP3N##i.method i.block) ///
(minW c.votes_minWw1LPP3N##i.method i.block) /// 
 , small dfk coeflegend 
 estimates store SUREG_QVLik



test _b[Gender:1.method#c.votes_genderw1LPP3N] + ///
_b[child2:1.method#c.votes_paidLw1LPP3N]+ ///
_b[gunOa:1.method#c.votes_gunOaw1LPP3N] + ///
_b[Black:1.method#c.votes_Blackw1LPP3N] + ///
_b[minW:1.method#c.votes_minWw1LPP3N] = 0 
matrix EV_tabG11[1,2] = r(F)
matrix EV_tabG11[2,2] = r(p)


restore


preserve

drop if method == 3

recode method (1 = 0) (2 = 1)

qui sureg (Gender c.votes_genderw1LPP3N##i.method i.block) ///
(child2 c.votes_paidLw1LPP3N##i.method i.block) ///
(gunOa c.votes_gunOaw1LPP3N##i.method i.block) ///
(Black c.votes_Blackw1LPP3N##i.method i.block) ///
(minW c.votes_minWw1LPP3N##i.method i.block) /// 
 , small dfk coeflegend 
 estimates store SUREG_LikL



test _b[Gender:1.method#c.votes_genderw1LPP3N] + ///
_b[child2:1.method#c.votes_paidLw1LPP3N]+ ///
_b[gunOa:1.method#c.votes_gunOaw1LPP3N] + ///
_b[Black:1.method#c.votes_Blackw1LPP3N] + ///
_b[minW:1.method#c.votes_minWw1LPP3N] = 0 
matrix EV_tabG11[1,3] = r(F)
matrix EV_tabG11[2,3] = r(p)

restore


cd "$pathtab"


esttab SUREG_LQV SUREG_LikL SUREG_QVLik  using sureg_mat.tex, replace ///
style(tex) cells(b(star fmt(2)) se(par(( )) fmt(2))) starlevels(* .05 ** .01 *** .001) ///
stats(N, fmt(0)) ///
title(Differences in Coefficient Size (SUR): Exposure Outcomes \label{suregmat}) ///
varlabels(_cons \_cons ///
1.method#c.votes_genderw1LPP3N Gender ///
1.method#c.votes_paidLw1LPP3N Prox_childB ///
1.method#c.votes_gunOaw1LPP3N No_Gun ///
1.method#c.votes_Blackw1LPP3N Black ///
1.method#c.votes_minWw1LPP3N Min_wage) /// 
keep(1.method#c.votes_genderw1LPP3N ///
1.method#c.votes_paidLw1LPP3N 1.method#c.votes_gunOaw1LPP3N ///
1.method#c.votes_Blackw1LPP3N 1.method#c.votes_minWw1LPP3N) 


esttab  matrix(EV_tabG11, fmt("0 3")) using sureg_mat2.tex, replace


**********************************************************
* OUTPUT TAB G11                        				 *
* PLEASE RUN CORRESPONDING LATEX FILE AVAILABLE IN "TAB" *
**********************************************************


erase "$pathtemp/ids_dataset_final.dta" 
erase "$pathtemp/ids_wave2.dta"

log close

